﻿
@{
    ViewBag.Title = "确认指导价";
    var order = ViewBag.Order as CubicFWNet.Data.ViewModal.OrderInfo;
    var opList = ViewBag.OpList as IEnumerable<CubicFWNet.Data.ViewModal.ProductView>;
}


<section class="content-header">
    <h1>
        确认指导价
    </h1>
    <ol class="breadcrumb">
        <li><a href="javascript:void(0);"><i class="fa fa-dashboard"></i>@Resources.Global.PageTitle</a></li>
        <li><a href="@Url.Action("Index","Home")">首页</a></li>
        <li class="active">确认指导价</li>
    </ol>
</section>

<section class="content">
    <form class="form-horizontal" method="post" id="formMain">
        <div class="box box-solid">
            <div class="box-body">
                <div class="row">
                    <input type="hidden" name="OrderID" id="OrderID" value="@order.Id" />

                    <div class="form-group col-md-6 col-sm-12" style="display:none">
                        <label for="Number" class="col-sm-3 control-label">订单编号</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" id="Number" name="Number" value="@order.Number" readonly />
                        </div>
                    </div>

                    <div class="form-group col-md-6 col-sm-12">
                        <label for="CusName" class="col-sm-3 control-label">客户名称</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" id="CusName" name="CusName" value="@order.CustomerName" readonly />
                        </div>
                    </div>

                    <div class="form-group col-md-6 col-sm-12" style="display:none">
                        <label for="InitPrice" class="col-sm-3 control-label">订单总价</label>
                        <div class="col-sm-9">
                            <input type="number" class="form-control" id="InitPrice" name="InitPrice" value="@order.InitPrice" readonly />
                        </div>
                    </div>
                </div>
            </div>
            <input type="hidden" id="Data" name="Data" />
            <div id="divProList ">
                @foreach (var item in opList)
                {
                    <div class="row panelLayout" id="@item.Id">
                        <div class="form-group col-md-6 col-sm-12">
                            <label class="col-sm-3 control-label">产品名称</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" value="@item.Name" readonly />
                            </div>
                        </div>

                        <div class="form-group col-md-6 col-sm-12">
                            <label class="col-sm-3 control-label">产品数量</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control ProAmount" value="@item.Amount" readonly />
                            </div>
                        </div>

                        <div class="form-group col-md-6 col-sm-12">
                            <label class="col-sm-3 control-label">成本价</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control ProCost" value="@item.Price" readonly />
                            </div>
                        </div>

                        <div class="form-group col-md-6 col-sm-12">
                            <label class="col-sm-3 control-label">参考价</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control ProFinal" id="@item.Id" value="@item.Price" readonly />
                            </div>
                        </div>

                        <div class="form-group col-md-6 col-sm-12">
                            <label class="col-sm-3 control-label">利润比</label>
                            <div class="col-sm-9">
                                <input type="number" class="form-control ProRatio" placeholder="例： 若利润比为25%，请输入0.25；若无利润比，请输入0。" />
                            </div>
                        </div>
                    </div>
                }
            </div>

            <div class="row">

            </div>
        </div>
        <div class="box-footer">
            <div class="box-footer">
                <span class="btn btn-primary " onclick="FormSub()">确 定</span>&nbsp;&nbsp;&nbsp;&nbsp;
                <a class="btn btn-primary" href="@Url.Action("Index","Product")">返 回</a>&nbsp;&nbsp;&nbsp;&nbsp;
                <label class="danger">@ViewBag.Info</label>
                <div class="text-red" style="margin-top:20px;font-weight:bold">下一步：产品管理-->提交最终价</div>
            </div>
        </div>
    </form>
</section>
<script src="~/Scripts/jQuery/jquery-2.2.3.min.js"></script>
<script>
    //产品种类数
    var num = $(".ProRatio").size();

    //获取Json数据
    function getParam() {
        var postdata = [];
        for (i = 0; i < num; i++) {
            var $this = $(".ProFinal").eq(i);
            var id = $this.attr('id');
            var value = $this.val();
            postdata.push({ ID: id, Price: value });
        }
        return JSON.stringify(postdata);
    }

    //提交数据
    function FormSub() {
        var num = $(".ProRatio").size();
        for (i = 0; i < num; i++)
        {
            var ratio = $(".ProRatio").eq(i).val();
            if (ratio == null || ratio == "" ) {
                $.modalAlert("请输入每个产品的利润比！", "warning");
                return false;
            }
            else if( ratio < 0)
            {
                $.modalAlert("利润比不能为负数！", "warning");
                return false;
            }
        }

        var data = getParam();
        $("#Data").val(data);
        $("#formMain").submit();
    }

    //验证利润比
    $(".ProRatio").blur(function () {
        var ratio = $(this).val();

        console.log(ratio);
        if (ratio == null || ratio == "" ) {
            $.modalAlert("请输入每个产品的利润比！", "warning");
            return false;
        }
        else if (ratio < 0) {
            $.modalAlert("利润比不能为负数！", "warning");
            return false;
        }

        var ind = $(".ProRatio").index($(this));
        var price = $(".ProCost").eq(ind).val();
        ratio = parseFloat(ratio);
        $(".ProFinal").eq(ind).val((price * (ratio + 1)).toFixed(2));
    })
</script>